//
//  LoginViewController.m
//  TenThousand
//
//  Created by 我的 on 16/6/22.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "ABProgressView.h"

@interface LoginViewController ()
{
    NSInteger a;
    NSInteger b;
}
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;
@property (weak, nonatomic) IBOutlet UIView *backView;
@property (weak, nonatomic) IBOutlet UIImageView *rightBtn;

@property (weak, nonatomic) IBOutlet UIButton *agreedBtn;//同意按钮
@property (weak, nonatomic) IBOutlet UITextField *mobileNum;//填写手机号
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"手机号";
    a = 0;
    b = 0;
    
    [self createLeft:[UIImage imageNamed:@"ZHSZicon_03"] leftClick:^{
        [self.navigationController popViewControllerAnimated:YES];
    } right:nil rightClick:nil];
    
   
    _nextBtn.enabled = NO;
    ABProgressView *abview = [[ABProgressView alloc]initWithFrame:CGRectMake(45, 5, Screen_Width-130, 50)];
    [_backView addSubview:abview];
    abview.leftPercent = ^void(CGFloat FT) {
        NSLog(@"+++++++%f",FT);
        if (FT == 1) {
             _rightBtn.image = [UIImage imageNamed:@"agreeImg"];
            
            self.agreedBtn.selected = YES;
             _nextBtn.enabled = YES;
            a = 1;
        }else{
           _nextBtn.enabled = NO;
            
           
        }
       
//        if (a == 1 && b == 1) {
//            _nextBtn.enabled = YES;
//        }else{
//            _nextBtn.enabled = NO;
//        }
        
    };

}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.mobileNum resignFirstResponder];
}

/**
 *  是否选中同意按钮
 *  选中 进行下一步
 *  未选中  下一步按钮enabled设为NO
 */

- (IBAction)agreeClicked:(UIButton *)sender {
    
    if (sender.selected) {
        sender.selected = NO;
      //  _nextBtn.enabled = NO;
    }else{
        b = 1;
        sender.selected = YES;
     //   _nextBtn.enabled = YES;
    }
    if (a == 1 && b == 1) {
        _nextBtn.enabled = YES;
    }else{
        _nextBtn.enabled = NO;
    }
    
}

//下一步  调到注册、登录页面
- (IBAction)nextBtn:(id)sender {
    
    //判断输入的手机号码是否为合法
    if (![PhoneNumStandard isStandardOrNotWithPhoneNumber:_mobileNum.text]) {
        [ToastView showInfoWithStatus:@"手机号输入不合法，请重新输入"];
    }else{
        RegisterViewController *registerView = [[RegisterViewController alloc] init];
        [self setHidesBottomBarWhenPushed:YES];
        registerView.mobile = [NSString stringWithFormat:@"%@",_mobileNum.text];//将手机号传到下一页注册
        //    NSLog(@"%@",registerView.mobile);
        [self.navigationController pushViewController:registerView animated:YES];
        
    }

}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{
    
    [self.view.window endEditing:YES];
    
}

@end
